package com.cheyun.netsalev3.view.guide


import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.core.content.ContextCompat
import com.cheyun.netsalev3.R
import com.cheyun.netsalev3.databinding.FragmentGuideBinding
import com.cheyun.netsalev3.utils.BaseFragment
import com.cheyun.netsalev3.view.LoginActivity

class GuideFragment : BaseFragment<FragmentGuideBinding>() {
    override fun initContentView(): Int {
        return R.layout.fragment_guide
    }

    override fun initView() {
        context?.apply {
            binding.rootView.background = ContextCompat.getDrawable(this, imgId)
        }
        if (pos == 3) {
            binding.startBut.visibility = View.VISIBLE
        } else {
            binding.startBut.visibility = View.GONE
        }
        var moth: (it: View) -> Unit = {
            startActivity(Intent(context, LoginActivity::class.java))
            activity?.finish()
        }
        binding.startBut.setOnClickListener(moth)
    }

    override fun initData() {
    }

    override fun lazyInit() {
        Log.i(TAG,"override lazyinit")
    }

    var pos = 0
    var imgId = R.drawable.welcome_1
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        arguments?.apply {
            pos = getInt("pos")
            imgId = getInt("imgId")
        }
    }

    companion object {
        @JvmStatic
        fun newInstance(pos: Int, imgId: Int) =
                GuideFragment().apply {
                    arguments = Bundle().apply {
                        putInt("pos", pos)
                        putInt("imgId", imgId)
                    }
                }

    }

}
